﻿import lite.mobile.lib.components.skin.CollectionSkins;
import lite.mobile.lib.components.skin.ISkin;
import lite.mobile.lib.components.IUComponent;

/**
 * @author alibber
 */
class lite.mobile.lib.components.UComponent implements IUComponent {

	private var _name : String ;
	private var _depth : Number = 0 ; 
	public var $_coreMC : MovieClip;
	public var $_enabled : Boolean = true;
	public var $_isCreateComplete:Boolean = false ;
	
	public function UComponent(name : String ,depth : Number) {
		if(!name) {
			_name = "_coreMC" + getTimer();
		} else {
			_name = name ;
		}
		_depth = depth ;
	}

	public function dependOnUI(ui : IUComponent) : Void {
		$_coreMC = ui.getChildMC(this);
		$_coreMC.tabChildren = false ;
		
		trace("//- : UComponent创建了$_coreMC..." + $_coreMC);
		trace(this._name);
		$_initSkin();
		$_initEvent();
		$_createComplete();
		_callOnCreateComplete();
	}

	public function getChildMC(ui : IUComponent) : MovieClip {
		var mc : MovieClip = $_coreMC.createEmptyMovieClip(ui.getName(), ui.getDepth());
		trace("//- : UComponent生成了子级mc..." + mc);
		trace(this._name);
		return mc ;
	}

	public function getCoreMC() : MovieClip {
		return $_coreMC ;
	}

	
	// feiqi
	/*	public function createCoreMC(site : MovieClip) : Void {
	if(!site) {
	return ;
	}
	if(!_depth) {
	_depth = site.getNextHighestDepth();
	}
	trace("==> " + _name + "    " + _depth);
	$_coreMC = site.createEmptyMovieClip(_name, _depth);
	}
	 */
	 
	 public function $_createComplete():Void {
	 	// null
	 }
	 
	private var _callOnCreateComplete: Function ;
	public function set onCreateComplete(fun : Function) : Void {
		_callOnCreateComplete = fun ;
	}

	public function getDepth() : Number {
		return _depth ;
	}

	public function getName() : String {
		return _name ;
	}

	public function $_initSkin() : Void {
		updateSkin(CollectionSkins.getInstance().getSkin(getType()));
	}

	public function $_initEvent() : Void {
	//null
	}

	public var $_skinMC : MovieClip;

	public function updateSkin(skin : ISkin) : Void {
	// null
	}

	public function getType() : String {
		return null;
	}

	public function setWidth(width : Number) : Void {
	//_width = width;
	}

	public function getWidth() : Number {
		return 0;//_width;
	}

	public function setHeight(height : Number) : Void {
	//_height = height;
	}

	public function getHeight() : Number {
		return 0;//_height;
	}

	private var _isKey : Boolean;

	// 是否启用了按键响应
	public function isKey() : Boolean {
		return _isKey;
	}

	// 按键被触发
	//public function setKey(code:Number):Void {
	//if (!_isKey) {
	//return;
	//}
	//}
	
	// 激活按键
	public function enabledKey() : Void {
		_isKey = true;
	}

	// 废除按键
	public function invalidismKey() : Void {
		_isKey = false;
	}

	private var _isFocus : Boolean;

	// 是否持有焦点
	public function isFocus() : Boolean {
		return _isFocus;
	}

	// 激活焦点
	public function enabledFocus() : Void {
		_isFocus = true;
	}

	// 废除焦点
	public function invalidismFocus() : Void {
		_isFocus = false;
	}

	// toString
	public function toString2() : String {
		return "111111111111111111111111111 ";//_name;
	}
}